import java.io.*;
import javax.bluetooth.*;
import lejos.nxt.comm.*;
import lejos.nxt.remote.*;
import lejos.devices.*;


public class Bluetooth {

	
	public void displayDevices(){
		LCD.clear();
	Vector list = bluetooth.getKnownDeviceList();
		if(list == null) 
			LCD.drawString("No Known device", 0, 1);
		else {
			for (int i = 0; i<list.size();i++){
				LCD.drawString("Device:" + ((RemoteDevice)list.elementAt(i)).getFriendlyName(false) + "\n", i, 1);
			}
		}
		Button.waitForPress();
	}
	
	
	public void findDevices(){
		byte[] cod = {0,0,0,0};
		LCD.clear();
		LCD.drawString("Searching... \n", 0, 1);
		Vector list = bluetooth.inquire(10,10,cod);
		if (list == null){
			LCD.drawString("No device found \n",0,1);
		}
		if(list.size() >0){
			for (int i = 0; i<list.size();i++){
				LCD.clear();
				LCD.drawString("Device:" + ((RemoteDevice)list.elementAt(i)).getFriendlyName(false) + "\n", i, 1);
				RemoteDevice device = ((RemoteDevice)list.elementAt(i));
				LCD.drawString("Add device to brick?",1,1);
				int button = Button.waitForPress();
				if (button ==1)
					Bluetooth.addDevice(device);																
			}
		}
		
		
	}
	
	
	public static void main(string args[]){
	findDevices();
	displayDevices();
	}
	
	
	
}
